Skip to content

Allow visit Sprite without camera for render to texture #17824

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 22, 2017

Conversation

madrazo
Copy link
Contributor

@madrazo madrazo commented May 16, 2017

A fix to allow render to texture like this

        Director::getInstance()->setProjection(Director::Projection::_2D);
        m_renderTarget->beginWithClear(1, 0, 0, 0.2, m_depthClear, 0);
        m_sprite->visit(Director::getInstance()->getRenderer(), Mat4::IDENTITY, 0);
        m_renderTarget->end();
        Director::getInstance()->setProjection(Director::Projection::_3D);

otherwise, crashes

PS: I have disabled the default camera in my Scene with

    _defaultCamera->setScene(NULL);
    removeChild(_defaultCamera);
    _defaultCamera = NULL;

A fix to allow render to texture like this 
'''
        Director::getInstance()->setProjection(Director::Projection::_2D);
        m_renderTarget->beginWithClear(1, 0, 0, 0.2, m_depthClear, 0);
        m_sprite->visit(Director::getInstance()->getRenderer(), Mat4::IDENTITY, 0);
        m_renderTarget->end();
        Director::getInstance()->setProjection(Director::Projection::_3D);
'''
@@ -1054,7 +1054,10 @@ void Sprite::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
// Don't calculate the culling if the transform was not updated
auto visitingCamera = Camera::getVisitingCamera();
auto defaultCamera = Camera::getDefaultCamera();
if (visitingCamera == defaultCamera) {
if (visitingCamera == NULL) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NULL -> nullptr

@minggo
Copy link
Contributor

minggo commented May 19, 2017

Interesting, why you set _defaultCamera to null?

@madrazo
Copy link
Contributor Author

madrazo commented May 19, 2017

I started using the USER cameras and then I saw that I didn't need the default camera.

Also, I think that when rendering to texture, the sprite was showing on the default camera on screen. Maybe I could add an extra USER camera for rendering to texture but this was more straightforward to me.

Furthermore, I'm not sure about this, but I see that some objects do some computation if there is a default camera on the "visit" or "render" functions when enter this if (visitingCamera == defaultCamera), so I try to avoid extra computations.

Thanks!

@madrazo
Copy link
Contributor Author

madrazo commented May 19, 2017

Interesting, why you set _defaultCamera to null?

Oh, you mean why I use this line? _defaultCamera = NULL;
Just to make sure that it is not used. But yeah, it may work if I don't do that line, or set the default camera to a different value

@minggo minggo added this to the 3.16 milestone May 22, 2017
@minggo minggo merged commit a24b40a into cocos2d:v3 May 22, 2017
stevetranby added a commit to stevetranby/cocos2d-x that referenced this pull request Jun 16, 2017
* commit '639737286f594f3e06c07b22b352dddb01858883':
  before draw event (cocos2d#17669)
  Handle auto layout with scaled widget (cocos2d#17822)
  fix to problem with updating APK in Google Play keeping old OBB (cocos2d#17689)
  update console to fix compiling issue on with Xcode 8.3+ (cocos2d#17862)
  Fix iskindof (cocos2d#17785)
  [ci skip][AUTO]: updating luabinding & jsbinding & cocos_file.json automatically (cocos2d#17857)
  fix action running times for instant actions (cocos2d#17849)
  make fps stable on iOS (cocos2d#17852)
  [ci skip][AUTO]: updating luabinding & jsbinding & cocos_file.json automatically (cocos2d#17848)
  LayerRadialGradient works on mac and iOS (cocos2d#17826)
  Fixing serious XMLHTTP leak when CC_ENABLE_GC_FOR_NATIVE_OBJECTS enabled (cocos2d#17844)
  Call 'update' method in 'stop/stopAll' to cleanup immediately (cocos2d#17846)
  Add const keyword to Node::isScheduled (cocos2d#17841)
  small BillBoard optimizations (cocos2d#17825)
  Allow visit Sprite without camera for render to texture (cocos2d#17824)

# Conflicts:
#	cocos/base/CCDirector.cpp
#	cocos/base/CCDirector.h
#	cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp
#	cocos/ui/UILayoutManager.cpp
#	tools/cocos2d-console
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants